home *** CD-ROM | disk | FTP | other *** search
- #include <string.h>
- #include "DalDemo.h"
-
- extern Str255 gPassword,gUsername, gNodename;
-
- /*** CreateSession ***/
- CreateSession()
- {
- DialogPtr logonDialog;
- int dialogDone = FALSE;
- int itemHit;
- int itemType;
- Rect itemRect;
- Handle itemHandle, OKHandle;
- demoPeek demoWind;
- Boolean doCreate;
-
- doCreate = FALSE;
- logonDialog = GetNewDialog(LOGON_DIALOG,NIL,(WindowPtr)MOVE_TO_FRONT);
- GetDItem(logonDialog, OK_BUTTON, &itemType, &OKHandle, &itemRect);
-
- ShowWindow(logonDialog);
- SetPort(logonDialog);
- DrawOKButton(logonDialog);
- gPassword[0] = NIL;
-
- while (!dialogDone)
- {
- if (gPassword[0] != NIL)
- HiliteControl(OKHandle, 0);
- else
- HiliteControl(OKHandle, 255);
-
- ModalDialog(SignonFilter,&itemHit);
- switch (itemHit)
- {
- case OK_BUTTON:
- GetDItem(logonDialog, LOGON_NODE, &itemType, &itemHandle, &itemRect);
- GetIText(itemHandle, gNodename);
- GetDItem(logonDialog, LOGON_NAME, &itemType, &itemHandle, &itemRect);
- GetIText(itemHandle, gUsername);
- doCreate = TRUE;
- case CANCEL_BUTTON:
- dialogDone = TRUE;
- HideWindow(logonDialog);
- break;
- }
- }
- if (doCreate)
- {
- SetCursor(*GetCursor(watchCursor));
- CreateWindow();
- demoWind = (demoPeek) FrontWindow();
- CtoPstr(gPassword);
- DALOpenLink(demoWind,gNodename, gUsername, gPassword);
- SetCursor(&arrow);
- }
- }
-
- /*** DrawOKButton ***/
- DrawOKButton(dp)
- DialogPtr dp;
- {
- int itemType;
- Rect itemRect;
- Handle item;
- GrafPtr oldPort;
-
- GetDItem(dp, OK_BUTTON, &itemType, &item, &itemRect);
- GetPort(&oldPort);
- SetPort( dp);
-
- PenSize(3,3);
- InsetRect(&itemRect,-4,-4);
- FrameRoundRect(&itemRect,16,16);
- PenNormal();
-
- SetPort(oldPort);
- }
-
-
- /*** SignonFilter ***/
- pascal Boolean SignonFilter(dp, theEvent, itemHit)
- DialogPtr dp;
- EventRecord *theEvent;
- int *itemHit;
- {
- Handle item;
- int itemType;
- Rect itemRect;
- char theChar;
- Str255 theStr;
- char frontStr[255],backStr[255];
- int selStart,selEnd;
- DialogPeek dPeek;
- int flag = FALSE;
-
- GetDItem( dp, LOGON_PSWD, &itemType, &item, &itemRect);
- GetIText( item, theStr);
-
- if ((theEvent->what == keyDown) || (theEvent->what == autoKey))
- {
- theChar = (theEvent->message & charCodeMask);
- dPeek = (DialogPeek) dp;
- switch (theChar)
- {
- case TE_CARRIAGE_RETURN:
- case TE_ENTER_KEY:
- if (theStr[0] != NIL)
- {
- *itemHit = OK_BUTTON;
- GetDItem(dp, OK_BUTTON, &itemType, &item, &itemRect);
- HiliteControl(item,1);
- return(TRUE);
- }
- else
- {
- *itemHit = LOGON_PSWD;
- return(TRUE);
- }
- break;
- case TE_TAB_CHAR:
- case TE_LEFT_ARROW:
- case TE_RIGHT_ARROW:
- case TE_UP_ARROW:
- case TE_DOWN_ARROW:
- break;
- case TE_BS_KEY:
- if (dPeek->editField == LOGON_PSWD - 1)
- {
- int len = 0;
- selStart = (**(dPeek->textH)).selStart;
- selEnd = (**(dPeek->textH)).selEnd;
- frontStr[0] = backStr[0] = NIL;
- if (selStart == selEnd)
- {
- if (selStart > 0)
- {
- strncpy(frontStr, (char *) gPassword, selStart-1);
- frontStr[selStart-1] = NIL;
- len = strlen((char *) gPassword) - selStart;
- strncpy(backStr, (char *)(gPassword+selStart),len);
- backStr[len] = NIL;
- strcpy((char *) gPassword,frontStr);
- strcat((char *) gPassword,backStr);
- }
- }
- else
- {
- strncpy(frontStr, (char *) gPassword, selStart);
- frontStr[selStart] = NIL;
- len = strlen((char *) gPassword) - selEnd;
- strncpy(backStr, (char *)(gPassword+selEnd),len);
- backStr[len] = NIL;
- strcpy((char *) gPassword,frontStr);
- strcat((char *) gPassword,backStr);
- }
- }
- break;
- default:
- if (dPeek->editField == LOGON_PSWD - 1)
- {
- selStart = (**(dPeek->textH)).selStart;
- selEnd = (**(dPeek->textH)).selEnd;
- backStr[0] = NIL;
- strncpy(backStr, (char *)(gPassword+selEnd),strlen((char *) gPassword) - selEnd);
- gPassword[selStart] = theChar;
- gPassword[selStart + 1] = NIL;
- strcat((char *) gPassword,backStr);
- theEvent->message = (theEvent->message & 0xffffff00) + 165;
- }
- break;
- }
- }
- return(FALSE);
- }
-